; Badge-Dial V0.x - ; Next : convert R7 to visible (Page 2) ; : continue next digit automatially ;Connect White(Common) to out-3 Red(Busy) to In-0, Blue(Pulse) to In-1 (nice 1:1 with plug) ; Initialiazation ; Output reg is all zeros, ie GND. Input Reg visible on Page0 00: "NOP" 01: "NOP" 02: MOV R0,#4 ; Set clock 03: MOV [#F1],R0 ; to 0.3ms 04: "NOP" 05: "NOP" 06: "NOP" 07: "NOP" 08: "NOP" 09: MOV R2,#1 ; debug, show we're here ; === MAIN === ; Start here scanning for a digit LoopNew: ; wait for Busy going low 0A: BIT IN,#0 ; Test bit 0 in R11 (OP-Y-Code is 0b1100) 0B: SKIP Z,1 ; Skip if Zero 0b10xx (ie Clear) xx=01 0C: JR LoopNew ; Back to loop if set 0D: MOV R2,#2 ; debug-show we're here 0E: "NOP" 0F: "NOP" ; Wait for pulse 10: MOV R7,#0 ; Counter of pulses LoopDigit: 11: BIT IN,#0 ; Have we stopped being busy? (Busy gone High) 12: SKIP Z,1 ; Skip if still busy : zero (0b10xx), ie low (skip=01) 13: JR Done ; No more pulses, done ( 30-14 = 1C ) 14: "NOP" 15: "NOP" 16: BIT IN,#1 ; A digit pulse? (Pulse High) 17: SKIP NZ,1 ; 18: JR LoopDigit ; (11-19=F8) not yet, try again 19: MOV PC,#05 ; Wait for debounce. Call Wait (addr 050) 1A: MOV JSR,#0 ; ->JSR->do the call 1B: INC R2 ;debug 1C: "NOP" 1D: "NOP" LoopEndPulse: 1E: BIT IN,#0 ; Have we stopped being busy? (Busy gone High) 1F: SKIP Z,1 ; Skip if still busy : zero (0b10xx), ie low (skip=01) 20: JR Done ; No more pulses, done ( 30-21 = 0F ) 21: BIT IN,#1 ; End of digit pulse? (Pulse Low) 22: SKIP Z,1 ; 23: JR LoopEndPulse ; (1E-24=FA) no, keep waiting 24: "NOP" 25: MOV PC,#05 ; Wait for debounce. Call Wait (addr 050) 26: MOV JSR,#0 ; ->JSR->do the call 27: INC R2 ;debug ; count one and go around 28: INC R7 29: JR LoopDigit ; (11-2A=E7) ... "NOPs" ... ;== Done: 30: MOV R2,#F ;debug 31: MOV R0,R7 32: CP R0,#A ; is it the "0", 10 pulses? 33: SKIP NZ,1 34: MOV R7,#0 ; yes, adjust count ; R7 now has the number 35: "NOP" 36: : ; === Display the digit in readable form on display 40: MOV R0,#8 ; set display 41: MOV [#F0],R0 ; page 8/9 42: MOV PC,#10 ; Call 43: MOV JSR,#0 ; Clear Display 44: INC PCM ; Compute address #110 + R7 * #10 45: ADD PCM,R7 ; 46: MOV JSR,#0 ; Call display that digit 47: "NOP" 48: "NOP" 49: "NOP" 4A: MOV PC,#00 ; (long) jump 4B: MOV PCL,#A ; to LoopNew ;==== Subroutines Wait: ; routine to wait for approx 5ms - ASSUMES clock is 0.3ms 50: MOV R3,#8 ; 8 times round the loop Waita: 51: DSZ R3 ; done it enough times? 52: JR Waita ; no, one more time 53: RET R0,#1 ; done (return value irellevant) == Display Disp_Clr: ; Clear Digit area on page 8/9 100: MOV R0,#0 ; all Off 101: MOV R8,#8 ; page 8 102: MOV R9,#9 ; 9 103: MOV R4,#3 ; offset in page 104: MOV R3,#7 ; lines to clear Disp_Row: 105: MOV [R8,R4],R0 ; clear right 106: MOV [R9,R4],R0 ; clear left 107: INC R4 ; next offset 108: DSZ R3 ; done? 109: JR Disp_Row 10A: RET #E ; leaving R8/R9 pointing to page, R0=#E : "NOP" Disp_0: ; display zero 110: MOV [#83],R0 111: MOV [#89],R0 112: MOV R0,#1 ; line on edge 113: MOV R4,#4 ; offset in page 114: MOV R3,#5 ; lines Disp_0a: 115: MOV [R8,R4],R0 ; draw right 116: MOV [R9,R4],R0 ; draw left 117: INC R4 118: DSZ R3 119: JR Disp_0a 11A: RET #0 : "NOP" Disp_1: 120: MOV [#89],R0 ; middlebar at bottom 121: MOV R0,#C ; 122: MOV [#84],R0 123: MOV R0,#4 124: MOV [#83],R0 ; vertical stroke 125: MOV [#85],R0 126: MOV [#86],R0 127: MOV [#87],R0 128: MOV [#88],R0 129: RET #1 : "NOP" Disp_2: 130: MOV R0,#2 ; dummy 131: MOV [#83],R0 132: RET #2 ; NB: tricky, wont fit, need to overflow somewhere : "NOP" Disp_3: 140: MOV [#83],R0 ; horizontal lines 141: MOV [#85],R0 142: MOV [#89],R0 143: MOV R0,#1 ; vertical lines at side 144: MOV [#84],R0 145: MOV [#86],R0 146: MOV [#87],R0 147: MOV [#88],R0 148: RET #3 : "NOP" Disp_4: 150: MOV R0,#4 151: MOV [#83],R0 152: MOV [#87],R0 153: MOV [#88],R0 154: MOV [#89],R0 155: MOV [#85],R0 156: MOV R0,#C 157: MOV [#84],R0 158: MOV R0,#F 159: MOV [#86],R0 15A: MOV R0,#1 15B: MOV [#95],R0 15C: MOV [#96],R0 15D: RET #4 : "NOP" Disp_5: 160: MOV [#83],R0 161: MOV [#85],R0 162: MOV [#89],R0 163: MOV R0,#1 164: MOV [#86],R0 165: MOV [#87],R0 166: MOV [#88],R0 167: MOV [#93],R0 168: MOV [#94],R0 169: MOV [#95],R0 16A: MOV [#99],R0 16B: RET #5 : "NOP" Disp_6: 170: MOV R0,#6 ; dummy 171: MOV [#87],R0 172: RET #6 : "NOP" Disp_7: 180: MOV R0,#F ; top bar 181: MOV [#83],R0 182: MOV R0,#1 ; Side line 183: MOV [#84],R0 184: MOV [#85],R0 185: MOV [#86],R0 186: MOV R0,#2 187: MOV [#87],R0 188: MOV [#88],R0 189: MOV [#89],R0 18A: RET #7 : "NOP" Disp_8: 190: MOV R0,#8 ; dummy 191: MOV [#88],R0 192: RET #8 : "NOP" Disp_9: 1A0: MOV R0,#9 ; dummy 1A1: MOV [#89],R0 1A2: RET #9